// UITeZheng5Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "JianAiSSQ.h"
#include "UITeZheng5Dlg.h"
#include "help.h"
#include "IniFile.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CUITeZheng5Dlg dialog


CUITeZheng5Dlg::CUITeZheng5Dlg(CWnd* pParent /*=NULL*/)
	: CTabPageSSL(CUITeZheng5Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUITeZheng5Dlg)
	m_strPD11 = _T("");
	m_strPD12 = _T("");
	m_strPD13 = _T("");
	m_strPD14 = _T("");
	m_strPD15 = _T("");
	m_strPD16 = _T("");
	m_strPD17 = _T("");
	m_strPD18 = _T("");
	m_strPD19 = _T("");
	m_strPD20 = _T("");
	//}}AFX_DATA_INIT
	m_pDlgAnalyze = NULL;

}


void CUITeZheng5Dlg::DoDataExchange(CDataExchange* pDX)
{
	CTabPageSSL::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUITeZheng5Dlg)
	DDX_Text(pDX, IDC_EDIT_PIANDU11, m_strPD11);
	DDX_Text(pDX, IDC_EDIT_PIANDU12, m_strPD12);
	DDX_Text(pDX, IDC_EDIT_PIANDU13, m_strPD13);
	DDX_Text(pDX, IDC_EDIT_PIANDU14, m_strPD14);
	DDX_Text(pDX, IDC_EDIT_PIANDU15, m_strPD15);
	DDX_Text(pDX, IDC_EDIT_PIANDU16, m_strPD16);
	DDX_Text(pDX, IDC_EDIT_PIANDU17, m_strPD17);
	DDX_Text(pDX, IDC_EDIT_PIANDU18, m_strPD18);
	DDX_Text(pDX, IDC_EDIT_PIANDU19, m_strPD19);
	DDX_Text(pDX, IDC_EDIT_PIANDU20, m_strPD20);
	//}}AFX_DATA_MAP
}
CUITeZheng5Dlg::~CUITeZheng5Dlg()
{
	if (m_pDlgAnalyze)
	{
		delete m_pDlgAnalyze;
		m_pDlgAnalyze = NULL;
	}
}


BEGIN_MESSAGE_MAP(CUITeZheng5Dlg, CTabPageSSL)
	//{{AFX_MSG_MAP(CUITeZheng5Dlg)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU11, OnBtnTzPiandu11)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU12, OnBtnTzPiandu12)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU13, OnBtnTzPiandu13)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU14, OnBtnTzPiandu14)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU15, OnBtnTzPiandu15)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU16, OnBtnTzPiandu16)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU17, OnBtnTzPiandu17)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU18, OnBtnTzPiandu18)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU19, OnBtnTzPiandu19)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU20, OnBtnTzPiandu20)
	ON_BN_CLICKED(IDC_CHK_PIANDU11, OnChkPiandu11)
	ON_BN_CLICKED(IDC_CHK_PIANDU12, OnChkPiandu12)
	ON_BN_CLICKED(IDC_CHK_PIANDU13, OnChkPiandu13)
	ON_BN_CLICKED(IDC_CHK_PIANDU14, OnChkPiandu14)
	ON_BN_CLICKED(IDC_CHK_PIANDU15, OnChkPiandu15)
	ON_BN_CLICKED(IDC_CHK_PIANDU16, OnChkPiandu16)
	ON_BN_CLICKED(IDC_CHK_PIANDU17, OnChkPiandu17)
	ON_BN_CLICKED(IDC_CHK_PIANDU18, OnChkPiandu18)
	ON_BN_CLICKED(IDC_CHK_PIANDU19, OnChkPiandu19)
	ON_BN_CLICKED(IDC_CHK_PIANDU20, OnChkPiandu20)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUITeZheng5Dlg message handlers
void CUITeZheng5Dlg::ShowAnalyzeDlg()
{
	if (m_pDlgAnalyze)	
	{
		delete m_pDlgAnalyze;
		m_pDlgAnalyze = NULL;
	}

	m_pDlgAnalyze = new CUIAnalyzeDlg();
	m_pDlgAnalyze->Create(IDD_DIG_ANNALYZE,this);
	m_pDlgAnalyze->ShowWindow(SW_SHOW);
	CRect meRect;
	m_pDlgAnalyze->GetClientRect(&meRect);
	m_pDlgAnalyze->MoveWindow(G_RECT.left,G_RECT.bottom,
							  meRect.Width(),meRect.Height());

}
void CUITeZheng5Dlg::ShowChart(int nType)
{
	ShowAnalyzeDlg();

	CDataChart Data;
	Data.m_nYMax			= 22;
	Data.m_nYDiv			= 11;
	Data.m_nDataIndex		= nType; 
	Data.m_strYTitle		= G_SSQ_TZ_TITLE[Data.m_nDataIndex];
	Data.m_nType			= SSQ_TEZHENG_TYPE;
	m_pDlgAnalyze->m_DlgZouShi.SetChartData(Data);	

	Data.m_nYMin			= 0;
	Data.m_nYMax			= max_y_value(G_TZGL[Data.m_nDataIndex],60,G_END-G_START+1,Data.m_nYDiv);
	Data.m_nXMax			= num_value(G_TZGL[Data.m_nDataIndex],60);
	Data.m_strXTitle		= G_SSQ_TZ_TITLE[Data.m_nDataIndex];
	Data.m_strYTitle		= G_TZ_Y[Data.m_nDataIndex];
	m_pDlgAnalyze->m_DlgTongJi.SetChartData(Data);

	m_pDlgAnalyze->UpdateYuCeData(Data.m_nType,Data.m_nDataIndex);
}

bool CUITeZheng5Dlg::GetTZYuCe()
{
	ConvertStr2Int(m_strPD11, tz_pd11);
	ConvertStr2Int(m_strPD12, tz_pd12);
	ConvertStr2Int(m_strPD13, tz_pd13);
	ConvertStr2Int(m_strPD14, tz_pd14);
	ConvertStr2Int(m_strPD15, tz_pd15);
	ConvertStr2Int(m_strPD16, tz_pd16);
	ConvertStr2Int(m_strPD17, tz_pd17);
	ConvertStr2Int(m_strPD18, tz_pd18);
	ConvertStr2Int(m_strPD19, tz_pd19);
	ConvertStr2Int(m_strPD20, tz_pd20);

	return true;
}
bool CUITeZheng5Dlg::UpdateTZData()
{
	UpdateData(TRUE);
	
//	if (!CheckInputFormat())
//		return false;

	if (!((CButton*)GetDlgItem(IDC_CHK_PIANDU11))->GetCheck())
		m_strPD11.Empty();
	if (!((CButton*)GetDlgItem(IDC_CHK_PIANDU12))->GetCheck())
		m_strPD12.Empty();

	GetTZYuCe();
	
	return true;
}

void CUITeZheng5Dlg::OnBtnTzPiandu11() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD11_TYPE);
}

void CUITeZheng5Dlg::OnBtnTzPiandu12() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD12_TYPE);
	
}

void CUITeZheng5Dlg::OnBtnTzPiandu13() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD13_TYPE);
	
}

void CUITeZheng5Dlg::OnBtnTzPiandu14() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD14_TYPE);
	
}

void CUITeZheng5Dlg::OnBtnTzPiandu15() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD15_TYPE);
	
}

void CUITeZheng5Dlg::OnBtnTzPiandu16() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD16_TYPE);
	
}

void CUITeZheng5Dlg::OnBtnTzPiandu17() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD17_TYPE);
	
}

void CUITeZheng5Dlg::OnBtnTzPiandu18() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD18_TYPE);
	
}

void CUITeZheng5Dlg::OnBtnTzPiandu19() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD19_TYPE);
	
}

void CUITeZheng5Dlg::OnBtnTzPiandu20() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD20_TYPE);
	
}

void CUITeZheng5Dlg::OnChkPiandu11() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD11 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU11))->GetCheck();
	
}

void CUITeZheng5Dlg::OnChkPiandu12() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD12 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU12))->GetCheck();
	
}

void CUITeZheng5Dlg::OnChkPiandu13() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD13 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU13))->GetCheck();
	
}

void CUITeZheng5Dlg::OnChkPiandu14() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD14 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU14))->GetCheck();
	
}

void CUITeZheng5Dlg::OnChkPiandu15() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD15 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU15))->GetCheck();
	
}

void CUITeZheng5Dlg::OnChkPiandu16() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD16 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU16))->GetCheck();
	
}

void CUITeZheng5Dlg::OnChkPiandu17() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD17 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU17))->GetCheck();
	
}

void CUITeZheng5Dlg::OnChkPiandu18() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD18 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU18))->GetCheck();
	
}

void CUITeZheng5Dlg::OnChkPiandu19() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD19 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU19))->GetCheck();
	
}

void CUITeZheng5Dlg::OnChkPiandu20() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD20 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU20))->GetCheck();
	
}
bool CUITeZheng5Dlg::SetYuCeDataToFile(CString strFile)
{
	UpdateData(TRUE);
	if (strFile.IsEmpty())
		strFile = GetAppPath()+ETCFILENAME;

	CString strTmp;
	strTmp.Format("%d",G_CHECK_PD11);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD11",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD11)
	SetValueToEtcFile(strFile,"TEZHENG","PD11",(LPTSTR)(LPCTSTR)m_strPD11);

	strTmp.Format("%d",G_CHECK_PD12);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD12",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD12)
	SetValueToEtcFile(strFile,"TEZHENG","PD12",(LPTSTR)(LPCTSTR)m_strPD12);

	strTmp.Format("%d",G_CHECK_PD13);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD13",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD13)
	SetValueToEtcFile(strFile,"TEZHENG","PD13",(LPTSTR)(LPCTSTR)m_strPD13);

	strTmp.Format("%d",G_CHECK_PD14);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD14",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD14)
	SetValueToEtcFile(strFile,"TEZHENG","PD14",(LPTSTR)(LPCTSTR)m_strPD14);

	strTmp.Format("%d",G_CHECK_PD15);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD15",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD15)
	SetValueToEtcFile(strFile,"TEZHENG","PD15",(LPTSTR)(LPCTSTR)m_strPD15);

	strTmp.Format("%d",G_CHECK_PD16);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD16",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD16)
	SetValueToEtcFile(strFile,"TEZHENG","PD16",(LPTSTR)(LPCTSTR)m_strPD16);

	strTmp.Format("%d",G_CHECK_PD17);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD17",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD17)
	SetValueToEtcFile(strFile,"TEZHENG","PD17",(LPTSTR)(LPCTSTR)m_strPD17);

	strTmp.Format("%d",G_CHECK_PD18);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD18",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD18)
	SetValueToEtcFile(strFile,"TEZHENG","PD18",(LPTSTR)(LPCTSTR)m_strPD18);

	strTmp.Format("%d",G_CHECK_PD19);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD19",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD19)
	SetValueToEtcFile(strFile,"TEZHENG","PD19",(LPTSTR)(LPCTSTR)m_strPD19);

	strTmp.Format("%d",G_CHECK_PD20);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD20",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD20)
	SetValueToEtcFile(strFile,"TEZHENG","PD20",(LPTSTR)(LPCTSTR)m_strPD20);
	
	return true;

}
bool CUITeZheng5Dlg::GetYuCeDataFromFile(CString strFile)
{
	if (strFile.IsEmpty())
		strFile = GetAppPath()+ETCFILENAME;
	int iRet = -1;
	char szValue[MAX_PATH+1] = {0};
	int iCheck = 0;
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD11",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD11",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD11 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD11)
		SendDlgItemMessage(IDC_CHK_PIANDU11,BM_CLICK,0,0);
	}
	else
	{
		m_strPD11.Empty();
		if (G_CHECK_PD11)
		SendDlgItemMessage(IDC_CHK_PIANDU11,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD12",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD12",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD12 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD12)
		SendDlgItemMessage(IDC_CHK_PIANDU12,BM_CLICK,0,0);
	}
	else
	{
		m_strPD12.Empty();
		if (G_CHECK_PD12)
		SendDlgItemMessage(IDC_CHK_PIANDU12,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD13",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD13",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD13 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD13)
		SendDlgItemMessage(IDC_CHK_PIANDU13,BM_CLICK,0,0);
	}
	else
	{
		m_strPD13.Empty();
		if (G_CHECK_PD13)
		SendDlgItemMessage(IDC_CHK_PIANDU13,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD14",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD14",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD14 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD14)
		SendDlgItemMessage(IDC_CHK_PIANDU14,BM_CLICK,0,0);
	}
	else
	{
		m_strPD14.Empty();
		if (G_CHECK_PD14)
		SendDlgItemMessage(IDC_CHK_PIANDU14,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD15",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD15",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD15 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD15)
		SendDlgItemMessage(IDC_CHK_PIANDU15,BM_CLICK,0,0);
	}
	else
	{
		m_strPD15.Empty();
		if (G_CHECK_PD15)
		SendDlgItemMessage(IDC_CHK_PIANDU15,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD16",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD16",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD16 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD16)
		SendDlgItemMessage(IDC_CHK_PIANDU16,BM_CLICK,0,0);
	}
	else
	{
		m_strPD16.Empty();
		if (G_CHECK_PD16)
		SendDlgItemMessage(IDC_CHK_PIANDU16,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD17",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD17",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD17 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD17)
		SendDlgItemMessage(IDC_CHK_PIANDU17,BM_CLICK,0,0);
	}
	else
	{
		m_strPD17.Empty();
		if (G_CHECK_PD17)
		SendDlgItemMessage(IDC_CHK_PIANDU17,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD18",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD18",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD18 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD18)
		SendDlgItemMessage(IDC_CHK_PIANDU18,BM_CLICK,0,0);
	}
	else
	{
		m_strPD18.Empty();
		if (G_CHECK_PD18)
		SendDlgItemMessage(IDC_CHK_PIANDU18,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD19",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD19",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD19 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD19)
		SendDlgItemMessage(IDC_CHK_PIANDU19,BM_CLICK,0,0);
	}
	else
	{
		m_strPD19.Empty();
		if (G_CHECK_PD19)
		SendDlgItemMessage(IDC_CHK_PIANDU19,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD20",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD20",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD20 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD20)
		SendDlgItemMessage(IDC_CHK_PIANDU20,BM_CLICK,0,0);
	}
	else
	{
		m_strPD20.Empty();
		if (G_CHECK_PD20)
		SendDlgItemMessage(IDC_CHK_PIANDU20,BM_CLICK,0,0);
	}

	UpdateData(FALSE);
	
	return true;
}

